import { Injectable } from '@angular/core';
import { RequestService } from '../../../cores/services/request.service';
import { ApiData } from '../../../cores/classes/api-data.class';
import { SearchParams } from '../../../cores/classes/search-params';
import { Recharge } from '../interfaces/recharge.interfaces';
import { Observable } from 'rxjs';
// import { Pagination } from 'ng-tools-ui';
import { map } from 'rxjs/operators';


@Injectable()
export class RechargeService {

    constructor(private request: RequestService) { }

    /**
     * 栏目列表
     */
    // searchCrash(pagination: Pagination, search: SearchParams): Observable<ApiData> {
    //     return this.request.get('/store/announcement/search', pagination.getpageDataWith(search.values));
    // }
    listGoodsType(): Observable<ApiData> {
        return this.request.url('/managerapi/one/class/type/get');
    }
    /**
     * 删除列表
     */
    del(id: number): Observable<ApiData> {
        return this.request.delete('/managerapi/class/type/delete', { id });
    }

    /**
   * 添加列表
   * @param {Banner} banner
   */
    insertBanner(banner: Recharge): Observable<ApiData> {
        return this.request.post('/managerapi/class/type/add', banner);
    }


    /**
 * 上传图片
 * @param {File} 文件对象
 */

    uploadBanner(file: File): Observable<string> {
        return this.request.files('/managerapi/banner/upload/image', {}, [{ name: 'src', files: [file] }])
            .pipe(map<ApiData, string>(res => res.datas));
    }
    /**
   * 更新幻灯片
   * @param {Banner} banner 幻灯片数据
   */
    updateBanner(banner: Recharge): Observable<ApiData> {
        return this.request.put('/managerapi/class/type/update', banner);
    }
}
